package team.seekers.hula.question.questionDevelopBook.note.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import team.seekers.hula.question.questionDevelopBook.note.entity.dao.NoteDO;
import team.seekers.hula.question.questionDevelopBook.note.entity.dto.NoteAddDTO;
import team.seekers.hula.question.questionDevelopBook.note.entity.dto.NoteUpdateDTO;
import team.seekers.hula.question.questionDevelopBook.note.entity.vo.NoteListVO;
import team.seekers.hula.question.questionDevelopBook.note.mapper.NoteMapper;
import team.seekers.hula.common.entity.PageResult;
import team.seekers.hula.record.mind.service.MindService;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * flomo小记 服务实现类
 * </p>
 *
 * @author hbc
 * @since 2021-02-15
 */
@Service
public class NoteService extends ServiceImpl<NoteMapper, NoteDO> {

    @Resource
    private MindService mindService;

    public String save(NoteAddDTO noteAddDTO) {
        NoteDO noteDO = new NoteDO();
        BeanUtils.copyProperties(noteAddDTO,noteDO);
        save(noteDO);

        // TODO:生成mind

        return noteDO.getId();
    }

    public void delete(String id) {
        removeById(id);

        // TODO:删除mind
    }

    public void update(NoteUpdateDTO updateDTO) {
        lambdaUpdate().set(
                NoteDO::getContent,updateDTO.getContent()
        ).eq(NoteDO::getId,updateDTO.getId()).update();
    }


    public List<NoteListVO> queryNotesByBookId(String bookId, String userId) {
        List<NoteDO> noteDOList = lambdaQuery().eq(NoteDO::getBookId, bookId).eq(NoteDO::getUserId, userId).list();

        ArrayList<NoteListVO> noteListVOS = new ArrayList<>();
        for (NoteDO noteDO : noteDOList) {
            NoteListVO noteListVO = new NoteListVO();
            BeanUtils.copyProperties(noteDO,noteListVO);
            noteListVOS.add(noteListVO);
        }

        return noteListVOS;
    }

    public PageResult pageOthersOrderByTime(long pageNow, long pageSize, long noteId) {
        return null;
    }
}
